﻿//AcademicPlanner - course registration planning web app.
//Copyright (C) 2009  Boubacar Diallo

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AcademicPlanner.Framework.Helpers;

namespace AcademicPlanner.Presentation
{
	/// <summary>
	/// View(TModel) is the base class for all strongly typed view pages in the AcademicPlanner application.
	/// It encapsulates common view page functionality such as translation of string messages
	/// and setting of default properties.
	/// </summary>
	/// <typeparam name="TModel">The type of the model object of the strongly typed View.</typeparam>
	/// <since>1.0</since>
	public abstract class View<TModel> : ViewPage<TModel> where TModel : class
    {
		/// <summary>
		/// Format of page title; provides a placeholder for extra text.
		/// </summary>
		/// <since>1.0</since>
		protected string titleFormat;

		/// <summary>
		/// Heading to be displayed on the page.
		/// </summary>
		/// <since>1.0</since>
		protected string pageHeading = "";

		/// <summary>
		/// Information about the page.
		/// </summary>
		/// <since>1.0</since>
		protected string pageTip = "";

		/// <summary>
		/// Gets the instance of the <c>AcademicPlannerWebApp</c> this View is
		/// executing under.
		/// </summary>
		/// <seealso cref="P:AcademicPlannerWebApp.Current"/>
		/// <since>1.0</since>
		public new AcademicPlannerWebApp Application
		{
			get { return AcademicPlannerWebApp.Current; }
		}


		/// <summary>
		/// Initializes the page. This method is an override and sets the current <code>Culture</code>
		/// of the page to a value read from the session.
		/// </summary>
		/// <param name="e">The event to initialize the page.</param>
		/// <seealso cref="M:AcademicPlanner.Framework.Helpers.SessionHelper.GetUserCulture"/>
		/// <since>1.0</since>
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			titleFormat = Application.AppOwnerName + " - {0}";
			Culture = SessionHelper.GetUserCulture();
			Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
			Response.Cache.SetExpires(new DateTime(1960, 1, 1, 0, 0, 0, DateTimeKind.Utc));
			Response.Cache.SetValidUntilExpires(false);
		}

		/// <summary>
		/// Translates a string message from the application's source language to its current
		/// target language read from the session. This method is a convenience wrapper of
		/// <see cref="M:AcademicPlanner.Framework.Helpers.TranslationHelper.Translate"/> 
		/// for <code>View</code> objects.
		/// </summary>
		/// <param name="pText">The message to translate.</param>
		/// <returns>The translated message.</returns>
		/// <seealso cref="M:AcademicPlanner.Framework.Helpers.TranslationHelper.Translate"/>
		/// <since>1.0</since>
		public string Tr(string pText)
		{
			return TranslationHelper.Translate(pText, "Presentation");
		}
    }

}
